#!groovy

@Library('sharelib@master') _

def k8s = new org.devops.kubernetes()

//env
String namespace = "${env.namespace}"
String deployment = "${env.deployment}"
String imagever = "${env.imagever}"
String interf = "${env.interf}"

pipeline {
    agent any
    parameters {
        choice choices: ['back', 'front'], description: '前后端', name: 'interf'
        choice choices: ['ebopo', 'smartbox'], description: '项目', name: 'namespace'
        choice choices: ['vte-client', 'ebopo-client', 'ete', 'web-pc'], description: '程序名称', name: 'deployment'
        string defaultValue: '74110b5', description: '镜像版本', name: 'imagever', trim: false
    }

    stages{
        stage(updateImage){
            steps{
                script{
                    //获取deployment信息
                    def containerMes = k8s.GetDepolyment("${namespace}", "${deployment}", "${interf}")
                    //获取容器信息
                    img = containerMes[0]
                    name = containerMes[1]
                    println("container img: " + img)
                    println("container name: " + name)
                    k8s.UpdateDeployment("${namespace}", "${deployment}", img, name, "${imagever}", "${interf}")
                }
            }
        }    
    }
    post {
        always{
            script{
                println("always")
            }
        }
        success{
            script{
                println("success")
            }
        }
        failure{
            script{
                println("failure")
            }
        }
        aborted{
            script{
                println("aborted")
            }
        }
    }
}